package org.www.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.www.bean.Trees;
import org.www.dao.TreeDao;
import org.www.dao.UserDao;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class ApiAction extends ActionSupport {
	private List list;
	private UserDao userdao;
	private TreeDao treedao;
	private Integer id;
	private String uname;
	private Map map;
	
	public List getList() {
		return list;
	}
	public void setList(List list) {
		this.list = list;
	}
	
	public UserDao getUserdao() {
		return userdao;
	}
	public void setUserdao(UserDao userdao) {
		this.userdao = userdao;
	}
	public TreeDao getTreedao() {
		return treedao;
	}
	public void setTreedao(TreeDao treedao) {
		this.treedao = treedao;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getUname() {
		return uname;
	}
	public void setUname(String uname) {
		this.uname = uname;
	}
	public Map getMap() {
		return map;
	}
	public void setMap(Map map) {
		this.map = map;
	}
	public String checkUserName() {
		map=new HashMap<>();
		map.put("status", "ok");
		list=userdao.findUserByName(uname);
		if (list.size()>0) {
			map.put("message", "账户已存在");
			map.put("code", "1");
		}else {
			map.put("message", "账户可以使用");
			map.put("code", "0");
		}
		return SUCCESS;
	}
	private List<Trees> list1;
	
	
	public List<Trees> getList1() {
		return list1;
	}
	public void setList1(List<Trees> list1) {
		this.list1 = list1;
	}
	public String showTree() {
		boolean panduan=ActionContext.getContext().getParameters().containsKey("id");
		list1=new ArrayList<>();
		if(!panduan) {
			id=0;
		}
		list1=treedao.findTreesById(id);
	//	if(!panduan) {
	//	直接写	id=0;
	//	}
		return SUCCESS;
	}
	
	

}
